package concurrence.lock;

public class DeadLock {
    public static void main(String[] args) {
        Thread a = new MyThreadA();
        Thread b = new MyThreadB();
        a.start();
        b.start();
    }
}
class MyThreadA extends Thread {
    @Override
    public void run() {
        System.out.println("================B===================");
        synchronized (A.A) {
            System.out.println("线程【" + Thread.currentThread().getName() + "】开始执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (B.B) {
            }
            System.out.println("线程【" + Thread.currentThread().getName() + "】执行结束。B.B = " + B.B + "; A.A = " + A.A);
        }
    }
}

class MyThreadB extends Thread {
    @Override
    public void run() {
        System.out.println("================B===================");
        synchronized (B.B) {
            System.out.println("线程【" + Thread.currentThread().getName() + "】开始执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (A.A) {
            }
            System.out.println("线程【" + Thread.currentThread().getName() + "】执行结束。B.B = " + B.B + "; A.A = " + A.A);
        }
    }
}
class A {
    static final Integer A = new Integer(1);
}

class B {
    static final Integer B = new Integer(1);
}
